package com.genius.workflow.log;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;


import com.fasterxml.jackson.annotation.JsonFormat;

/**
 * 用户操作行为记录
 * @author woy
 *
 */
public class Geniuslog implements Serializable{
	private String logId;           //日志主键  
    private String type;            //日志类型  
    private String title;           //日志标题  
    private String remoteAddr;          //请求地址  
    private String requestUri;          //URI   
    private String method;          //请求方式  
    private String params;          //提交参数  
    private String exception;           //异常    
    
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private String operateDate;           //开始时间  
    private String timeout;         //结束时间  
    private String userId;   //用户ID
    private String resultParams;  //   //返回参数
	public String getLogId() {
		return logId;
	}
	public void setLogId(String logId) {
		this.logId = logId;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getRemoteAddr() {
		return remoteAddr;
	}
	public void setRemoteAddr(String remoteAddr) {
		this.remoteAddr = remoteAddr;
	}
	public String getRequestUri() {
		return requestUri;
	}
	public void setRequestUri(String requestUri) {
		this.requestUri = requestUri;
	}
	public String getMethod() {
		return method;
	}
	public void setMethod(String method) {
		this.method = method;
	}
	public String getParams() {
		return params;
	}
	public void setParams(String params) {
		this.params = params;
	}
	/**
     * 设置请求参数
     * @param paramMap
     */
    public void setMapToParams(String params) {
        if (params == null){
            return;
        }
        this.params = params;
    }

	public String getException() {
		return exception;
	}
	public void setException(String exception) {
		this.exception = exception;
	}
	public String getOperateDate() {
		return operateDate;
	}
	public void setOperateDate(String operateDate) {
		this.operateDate = operateDate;
	}
	public String getTimeout() {
		return timeout;
	}
	public void setTimeout(String timeout) {
		this.timeout = timeout;
	}
	public String getUserId() {
		return userId;
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}
	public String getResultParams() {
		return resultParams;
	}
	public void setResultParams(String resultParams) {
		this.resultParams = resultParams;
	}

    private String abbr (String str,int length){
    	if(str.equals(""))
    		return "";
    	StringBuilder sb = new StringBuilder();
    	int currentLength = 0;
    	try {
			for(char c:str.toCharArray()){
				currentLength += String.valueOf(c).getBytes("utf-8").length;
				if(currentLength <= length-3){
					sb.append(c);
				}else{
					sb.append("...");
					break;
				}
			}
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	return sb.toString();
    }
    public String toString(){
    	String result = String.format("来自【%s】用户,请求地址为【%s】,请求方式为【%s】,请求参数为【%s】,开始时间为【%s】,耗时【%s】,登入【%s】,返回参数为【%s】,发送异常【%s】"
    			, this.userId,this.remoteAddr,this.method,this.params,this.operateDate,this.timeout,this.title,this.resultParams,this.exception);
    	return result;
    }
}
